jsontemplate.modelformatter = function() {
    var self = {};
    
    self.ModelFormatter = function(model) {
        return self.render(model, "");
    }

    self.render = function (model, level) {
        var s = ""; 
        if (typeof(model) != "object") {
            s += model;
            if (level == "") {
                s = jsontemplate.HtmlEscape(s);
            }
            return s;
        }
        s = "\n"
        if (model._meta) {
            s += level+"<strong>" + model._meta.name + "-" + model._meta.id + "</strong>\n";
        }
        for (var key in model) {
            // if (key == "_meta") continue;
            var val = model[key];
            key = String(key);
            val = self.render(val, level+"  ");
            val = (level == "") ? jsontemplate.HtmlEscape(val) : val;
            s += level+key+": "+val+"\n";
        }
        return (level == "") ? "<pre>"+s+"</pre>" : s;
    }
}();

